import 'package:flutter/material.dart';
import 'package:nft_shop/my/page/notice/home_noticelist_page.dart';
import 'package:nft_shop/widgets/custom_underline_tabIndicator.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';

class HomeMessagePage extends StatefulWidget {
  @override
  _HomeMessagePageState createState() => _HomeMessagePageState();
}

class _HomeMessagePageState extends State<HomeMessagePage> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin{
  TabController? _tabController;
  final PageController _pageController = PageController(initialPage: 0);

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(vsync: this, length: 2);

  }

  @override
  void dispose() {
    _tabController?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        centerTitle: "消息中心",
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          TabBar(
            onTap: (index) {
              if (!mounted) {
                return;
              }
              _pageController.jumpToPage(index);
            },
            labelPadding: EdgeInsets.zero,
            controller: _tabController,
            labelStyle: TextStyle(fontSize: 14,fontFamily: "PingFangSC-Semibold",),
            unselectedLabelStyle:TextStyle(fontSize: 14,fontFamily: "PingFangSC-Semibold",),
            indicatorSize: TabBarIndicatorSize.label,
            unselectedLabelColor: Color(0xFF999999),
            labelColor: Color(0xFF131415),
            indicatorPadding: EdgeInsets.only(bottom: 2,left: 3,right: 3),
            indicator: CustomUnderlineTabIndicator(borderSide: BorderSide(color: Color(0xFF131415),width: 3,)),
            tabs: const <Widget>[
              Tab(text: "系统公告",),
              Tab(text:"个人消息",),
            ],
          ),
          Divider(
            thickness: 1,
            color: Color(0xFFF7F7FA),
          ),
          Expanded(
              child: PageView.builder(
                key: const Key('pageView'),
                itemCount: 2,
                onPageChanged: _onPageChange,
                controller: _pageController,
                itemBuilder: (_, int index) {
                  return HomeNoticeListPage(
                    presentIndex: index,
                  );
                },
              ))
        ],
      ),
    );
  }
  void _onPageChange(int index) {
    _tabController?.animateTo(index);
  }

}
